import request from '../utils/request'

// 获取订单列表
export function getOrders(params) {
  return request({
    url: '/orders',
    method: 'get',
    params
  })
}

// 获取订单详情
export function getOrderById(id) {
  return request({
    url: `/orders/${id}`,
    method: 'get'
  })
}

// 创建订单
export function createOrder(data) {
  return request({
    url: '/orders',
    method: 'post',
    data
  })
}

// 更新订单状态
export function updateOrderStatus(id, status) {
  return request({
    url: `/orders/${id}/status`,
    method: 'put',
    data: { status }
  })
}

// 取消订单
export function cancelOrder(id) {
  return request({
    url: `/orders/${id}/cancel`,
    method: 'put'
  })
}

// 支付订单
export function payOrder(id) {
  return request({
    url: `/orders/${id}/pay`,
    method: 'put'
  })
}

// 获取我的订单
export function getMyOrders(params) {
  return request({
    url: '/orders/my',
    method: 'get',
    params
  })
}

// 获取商家订单
export function getMerchantOrders(params) {
  return request({
    url: '/orders/merchant',
    method: 'get',
    params
  })
}

// 获取配送员订单
export function getDeliveryOrders(params) {
  return request({
    url: '/orders/delivery',
    method: 'get',
    params
  })
}

// 获取待配送订单
export function getPendingOrders(params) {
  return request({
    url: '/orders/pending',
    method: 'get',
    params
  })
}

// 接单
export function acceptOrder(orderId) {
  return request({
    url: `/orders/${orderId}/accept`,
    method: 'put'
  })
}

// 开始配送
export function startDelivery(orderId) {
  return request({
    url: `/orders/${orderId}/start-delivery`,
    method: 'put'
  })
}

// 完成配送
export function completeDelivery(orderId) {
  return request({
    url: `/orders/${orderId}/complete`,
    method: 'put'
  })
}

// 确认收货
export function confirmOrder(orderId) {
  return request({
    url: `/orders/${orderId}/confirm`,
    method: 'put'
  })
}

// 获取用户订单列表
export function getUserOrders(params) {
  return request({
    url: '/user/orders',
    method: 'get',
    params
  })
}

// 获取今日统计
export function getTodayStats() {
  return request({
    url: '/orders/today-stats',
    method: 'get'
  })
}

// 获取最近订单
export function getRecentOrders(params) {
  return request({
    url: '/orders/recent',
    method: 'get',
    params
  })
}
